<template>
	<div>
		<el-button type="success" @click="doSubmit" v-if="this.goodsModel.editMode"> 保存商品信息 </el-button>
		<el-button 
			v-else 
			type="primary" 
			plain 
			@click="doAddGoods(goodsModel)" 
			:disabled="loadding" 
			element-loading-background="rgba(0, 0, 0, 0.8)">
			新增商品信息
		</el-button>
		<el-row style="margin:10px;"></el-row>
		<!-- queryColuMainInfo -->
		<el-tabs 
			v-model="activeName" 
			type="card" 
			@tab-click="handleClick">
			<el-tab-pane label="产品信息" name="tab1">
				<el-form ref="form" :model="goodsModel" label-width="100px">
					<el-row :gutter="24" style="margin-bottom: 22px;">
						<el-col :span="24">
							<div :span="3" class="el-form-item__label" style="width:100px">
								<span style="color: #fa5555;margin-right: 4px;">*</span>商品分类
							</div>
							<el-cascader :options="goodsOptions" v-model="goodsModel.catList" style="width:400px;" @change="handleCatfun()">
							</el-cascader>
						</el-col>
					</el-row>
					<el-row :gutter="24" style="margin-bottom: 22px;">
						<el-col :span="24">
							<div :span="3" class="el-form-item__label" style="width:100px">
								<span style="    color: #fa5555;margin-right: 4px;">*</span> 商品名称
							</div>
							<el-input v-model="goodsModel.goodsName" style="width:400px;" :placeholder="catfun" />
						</el-col>
					</el-row>
					<el-form-item label="商品品牌">
						<el-input v-model="goodsModel.goodsBrand" style="width:400px;" />
					</el-form-item>
					<el-form-item label="OEM号">
						<el-input v-model="goodsModel.oemCode" style="width:400px;" />
					</el-form-item>
					<el-form-item label="商品编号">
						<el-input v-model="goodsModel.goodsModelNumber" style="width:400px;" />
					</el-form-item>
					<el-form-item label="横向件专属码">
						<el-input v-model="goodsModel.exclusiveCode" style="width:400px;" />
					</el-form-item>
					<el-form-item label="颜色">
						<el-checkbox 
							:indeterminate="isIndeterminate" 
							v-model="checkAll" 
							@change="handleCheckAllChange">
							全选
						</el-checkbox>
						{{checkedCities}}
						<div style="margin: 15px 0;"></div>
						<el-checkbox-group v-model="checkedCities" @change="handleCheckedCitiesChange">
							<el-checkbox v-for="color in cities" :label="color" :key="color">
								<div style="display:flex;">
									<div style="width:1em; height:1em;background-color:#999" :style="handleColor(color)"></div>
									<div style="    margin: -1px 5px;">{{color}}</div>
								</div>
							</el-checkbox>
						</el-checkbox-group>
					</el-form-item>
					<el-form-item label="商品详情" v-loading="loadding">
						<div style="display:flex;    align-items: center;">
							<div class="el-upload el-upload--picture-card" style="" @click="handleUpload()">

								<img v-if="goodsModel.details" :src="goodsModel.details" style="    width: 100%;
    height: 100%;" />
								<span v-else>商品详情</span>
							</div>
							<input style="display:none" type="file" ref="logo" name="" id="" @change="handleCurrentFile();" />
							<el-button type="text" icon="el-icon-delete" style="margin:40px;" @click="goodsModel.details=''"></el-button>
						</div>
					</el-form-item>
					<el-form-item label="销售价">
						<el-col :span="6">
							<el-input v-model="goodsModel.marketPrice" style="width:200px;" />
							<span>元</span>
						</el-col>
						<el-col :span="6">
							<el-form-item>
								<el-checkbox label="含税价" name="type" v-model="goodsModel.taxStatus"></el-checkbox>
								<el-checkbox label="显示价格" name="type" v-model="goodsModel.priceShowStatus"></el-checkbox>
							</el-form-item>
						</el-col>
					</el-form-item>
					<el-form-item label="配件品质">
						<el-radio v-model="goodsModel.qualityRange" label="ORIGIN_TYPE">原厂件</el-radio>
						<el-radio v-model="goodsModel.qualityRange" label="BRAND_TYPE">品牌件</el-radio>
					</el-form-item>
					<el-form-item label="单位" v-if="unitList && unitList.length>0">
						<el-radio v-for="item in unitList" v-model="goodsModel.unit" :label="item.title">{{item.title}}</el-radio>
					</el-form-item>
					<div v-loading="loadding">
						<h3> <span style="color: #fa5555;margin-right: 4px;">*</span>商品封面图片</h3>
						<el-upload 
							:action="uploadModel.uploadUrl" 
							list-type="picture-card" 
							:on-preview="uploadModel.onPreview" 
							:on-remove="uploadModel.onRemove" 
							:on-success="uploadModel.onUploadSuccess" 
							:file-list="uploadModel.fileList" 
							:on-progress="uploadModel.progress" 
							:on-error="uploadModel.error" 
							:before-upload="uploadModel.onBefore">
							<i class="el-icon-plus"></i>
						</el-upload>
					</div>
					<div 
						v-if="this.goodsModel.editMode&&$store.getters.getModel.showModelRela === 'true'" 
						style="width:480px;    
						margin-bottom: 30px;">

						<el-table 
							:data="$refs.carMainModel.maintainCarList" 
							ref="maintainCarList" 
							highlight-current-row 
							max-height="500" 
							height="500">
							<el-table-column prop="modelName" label="适应车型" width="400">
								<template scope="scope">
									<span>{{scope.row.brandName}}&nbsp;{{scope.row.seriesName}}&nbsp;{{scope.row.modelName}} </span>
								</template>
							</el-table-column>
						</el-table>
						<div class="block" align="right">
							<br>
							<el-pagination 
								@current-change="$refs.carMainModel.handleCurrentProductChange" 
								layout=" prev, pager, next" 
								:page-size="20" 
								:total="$refs.carMainModel.pdcount">
							</el-pagination>
						</div>
					</div>
					<div v-if="this.goodsModel.editMode">
						<h3> 
							<span style="visibility:hidden;color:#fa5555;margin-right: 4px;">*</span>
							自定义信息 
          					<el-button 
          						size="small" 
          						type="info" 
          						plain 
          						@click="attrFormModel=true" 
          						style="margin:0 20px">
          						新增
          					</el-button>
                		</h3>
						<el-table :data="attributeList" style="width: 50%" height="500">
							<el-table-column label="属性名" sortable>
								<template scope="scope">
									<span 
										v-if="updateAttrModelId===scope.row.id">   
        							<el-input type="text" v-model="scope.row.attributeKey" /> </span>
									<span v-else>   
      									{{scope.row.attributeKey}} 
									</span>
								</template>
							</el-table-column>
							<el-table-column label="属性值" sortable>
								<template scope="scope">
									<span 
										v-if="updateAttrModelId===scope.row.id">   
        								<el-input type="text" v-model="scope.row.attributeValue" /> 
									</span>
									<span v-else> 
      									{{scope.row.attributeValue}} 
									</span>
								</template>
							</el-table-column>
							<el-table-column label="操作" width="300">
								<template scope="scope">
									<el-button 
										size="small" 
										:type="updateAttrModelId===scope.row.id?'success' :'primary' " 
										plain 
										@click="changeAttributeItem(scope.row)">
										{{updateAttrModelId===scope.row.id?'保存':'修改'}}
									</el-button>
									<el-button size="small" type="danger" plain="" @click="delAttr(scope.row)">删除</el-button>
								</template>
							</el-table-column>
						</el-table>
					</div>
					<el-dialog title="新增属性" :visible.sync="attrFormModel" width="50%" center top="10vh" :close-on-click-modal='false'>
						<el-form label-width="7em" v-model="attrForm">
							<el-form-item label="属性名">
								<el-input placeholder="属性值" v-model="attrForm.attributeName" />
							</el-form-item>
							<el-form-item label="属性值">
								<el-input placeholder="属性值" v-model="attrForm.attributeValue" />
							</el-form-item>
						</el-form>
						<span slot="footer" class="dialog-footer">
			              <el-button @click="attrFormModel=false">取消</el-button>
			              <el-button type="primary" @click="addattr()">确定</el-button>
			            </span>
					</el-dialog>
					<el-dialog :visible.sync="imageDialogModel.show">
						<img width="100%" :src="imageDialogModel.imageUrl" alt="">
					</el-dialog>
				</el-form>
			</el-tab-pane>
			<el-tab-pane label="价格信息" name="tab2" :disabled="!goodsModel.editMode" v-if=" $store.getters.getModel.seniorMall === 'true'">
				<goods-price-com :goods-id="goodsModel.goodsId" ref="goodsPriceModel"></goods-price-com>
			</el-tab-pane>
			<el-tab-pane label="技术信息" name="tab4" :disabled="!goodsModel.editMode">
				<car-maintain ref="carMainModel" :goods-id="goodsModel.goodsId" :cat-id="goodsModel.catId2"></car-maintain>
			</el-tab-pane>
		</el-tabs>
	</div>
</template>

<script>
	import * as Api from "@/api/Api.js";
	import * as Config from "@/api/Config.js";
	import * as CarApi from "@/api/CarApi.js";
	import carGoodsCom from "./com/CarGoodsCom";

	import goodsPriceCom from "./com/GoodsPriceCom";

	import * as RoundApi from "@/api/RoundApi.js";
	import carMaintain from "./com/CarMaintain";

	export default {
		data() {
			return {
				// 接受字典单位
				unitList: null,
				attrForm: {
					attributeName: "",
					attributeValue: ""
				},
				attrFormModel: false,
				updateAttrModelId: "",
				attributeList: [],
				activeName: "tab1",
				goodsOptions: [],
				imageDialogModel: {
					show: false,
					imageUrl: ""
				},
				uploadModel: {
					disabled: false,
					uploadUrl: "",
					fileList: [],
					onRemove: (file, fileList) => {
						console.log(file, this.uploadModel.fileList);
						console.log("删除", this.loadding);
						if(this.loadding) {
							this.loadding = false;
							return;
						}
						this.uploadModel.fileList = fileList;
					},
					onBefore: () => {
						if(this.loadding) {
							return false;
						}
					},
					onPreview: file => {
						this.imageDialogModel.imageUrl = file.url;
						this.imageDialogModel.show = true;
					},
					loadfun: res => {
						console.log(1, res);
						let dt = {
							name: "1.png",
							url: res.action
						};
						this.uploadModel.fileList.push(dt);
						console.log(this.uploadModel.fileList);
						this.loadding = false;
					},
					onUploadSuccess: (response, file, fileList) => {
						console.log("开始");
						let dt = {
							name: "1.png",
							url: response.data.filename
						};
						window.myvue.uploadModel.fileList.push(dt);
						console.log(window.myvue.uploadModel.fileList);

						this.loadding = false;
					},
					error: () => {
						this.loadding = false;
					},
					progress: () => {
						this.loadding = true;
					},
					doPreview: () => {}
				},
				loadding: false,
				catfun: "",
				goodsModel: {
					goodsId: "",
					editMode: false,
					marketPrice: 0.0,
					labelPrice: 0.0,
					qualityRange: "",
					goodsName: "",
					goodsBrand: "",
					imageList: "",
					taxStatus: false,
					priceShowStatus: false,
					oemCode: "",
					goodsModelNumber: "",
					exclusiveCode: '',
					price: 0.0,
					catList: [],
					catId1: "",
					catId2: "",
					color: "",
					details: ""
				},
				checkedCities: [],
				cities: [
					"白色",
					"黑色",
					"银色",
					"红色",
					"棕色",
					"绿色",
					"蓝色",
					"黄色",
					"紫色"
				],
				checkAll: false,
				isIndeterminate: false
			};
		},
		watch: {
			$route(to, from) {
				// 对路由变化作出响应...
				if(to.name === "addgoods") {
					Object.assign(this.$data, this.$options.data());
					this.getProDatil();
					this.$refs.carMainModel.maintainCarList = [];
					Api.queryCatTree(this).then(res => {
						if(res.retCode) {
							this.goodsOptions = res.data;
						}
					});
				}
			}
		},
		methods: {
			handleCurrentFile(index) {
				if(!this.$refs.logo.files[0]) {
					return;
				}
				let name = "file" + index;
				let form = new FormData();
				let logo = this.$refs.logo.files[0];
				form.append("file", logo);
				this.loadding = true;

				RoundApi.upLoadPicture(form).then(res => {
					console.log("上传", res);

					if(res.retCode) {
						this.goodsModel.details = res.data.filename;
						this.loadding = false;
					}
				});
			},
			handleUpload() {
				this.$refs.logo.click();
			},
			handleCheckAllChange(val) {
				this.checkedCities = val ? this.cities : [];
				this.isIndeterminate = false;
			},
			handleCheckedCitiesChange(value) {
				console.log(value);
				let checkedCount = value.length;
				this.checkAll = checkedCount === this.cities.length;
				this.isIndeterminate =
					checkedCount > 0 && checkedCount < this.cities.length;
			},
			handleColor(color) {
				switch(color) {
					case "白色":
						return "background-color:white";
					case "黑色":
						return "background-color:black";
					case "银色":
						return "background-color:#c0c0c0";
					case "红色":
						return "background-color:red";
					case "棕色":
						return "background-color:brown";
					case "绿色":
						return "background-color:green";
					case "蓝色":
						return "background-color:blue";
					case "黄色":
						return "background-color:yellow";
					case "紫色":
						return "background-color:purple";
					default:
						return "background-color:#fff";
				}
			},
			handleClick() {
				this.$refs.maintainCarList.doLayout();
				this.$refs.carMainModel.handleClick();
			},
			addattr() {
				if(
					this.attrForm.attributeName === "" ||
					this.attrForm.attributeValue === ""
				) {
					this.$message("请填写属性信息");
					return;
				}
				let model = {
					goodsId: this.goodsModel.goodsId
				};
				Object.assign(model, this.attrForm);
				Api.addPdAttribute(this, model).then(res => {
					if(!res.retCode) {
						this.$alert("添加失败");
						return;
					}
					this.attrFormModel = false;
					this.getPdAttribute();
				});
			},
			handleCatfun() {
				this.catfun = "";
				this.goodsOptions.forEach((item, index) => {
					if(item.catId === this.goodsModel.catList[0]) {
						if(this.goodsModel.catList.length > 1) {
							item.children.forEach((secCat, carIndex) => {
								if(secCat.catId === this.goodsModel.catList[1]) {
									this.catfun = secCat.catName;
									return;
								}
							});
						} else {
							this.catfun = item.catName;
							return;
						}
					}
				});
			},
			removeByValue(arr, val) {
				for(var i = 0; i < arr.length; i++) {
					if(arr[i] == val) {
						arr.splice(i, 1);
						break;
					}
				}
			},
			loadCarLink() {
				Api.queryGoodsCarLink(this, this.goodsId).then(res => {
					if(!res.retCode) {
						this.$alert("查询车型关联信息出错！");
						return;
					}
					this.carList = res.data;

					console.log(this.carList);
				});
			},
			getUnit() {
				console.log('字典')
				Api.unit().then(res => {
					console.log(res)
					if(res.retCode === true && res.data.length > 0) {
						res.data.forEach((item) => {
							item.select = false
						})
						this.unitList = res.data;
						console.log(this.unitList)
					}
				})
			},
			saveSelectCar() {
				let idList = [];
				this.editerData.selectedModel.forEach((item, index) => {
					idList.push(item.modelId);
				});
				CarApi.addGoodsCarLink(this.goodsModel.goodsId, idList).then(res => {
					console.log();
					if(res.retCode) {
						this.$message("添加车型数据成功");
						this.loadCarLink();
					} else {
						this.$alert("添加车型数据失败");
					}
				});
			},
			setSelected: function(val) {
				console.log(val);
				this.editerData.selectedModel = val;
			},
			//初始化筛选字段
			screenInit: function() {
				if(this.list.length > 0) {
					this.screenShow = !this.screenShow;
				} else {
					RoundApi.initFilterList().then(res => {
						if(res.retCode) {
							console.log("初始化", res);
							this.list = res.data;
							this.screenShow = !this.screenShow;
						}
					});
				}
			},

			setKeyIds: function(val) {
				this.keyIds = val;
			},
			onsubmit: function() {
				var params = new URLSearchParams();
				for(var i = 0; i < this.keyIds.length; i++) {
					params.append("keyIds", this.keyIds[i].keyId);
				}
				let count = true;
				for(var i = 0; i < this.list.length; i++) {
					if(this.list[i].text.trim() != "") count = false;
					params.append(this.list[i].keyId, this.list[i].text);
				}
				if(count) {
					this.$message("请填写至少一项筛选条件");
					return;
				}
				this.modelTableShow = true;

				this.modelTableLoading = true;

				this.isInitSelectnnnn = true;
				axios
					.post(Config.g_service_url + "/screen", params)
					.then(
						function(response) {
							console.log("筛选之后", response.data.data);
							this.modelData = response.data.data;

							this.selectCar({
								infoId: this.infoId
							});
							// this.initSelectnnnn();
						}.bind(this)
					)
					.catch(function(error) {});

				this.screenShow = false;
			},

			toFormObject(responseData) {
				let formData = {};

				Object.assign(formData, responseData);

				formData.catList = [responseData.catId1, responseData.catId2];

				this.uploadModel.fileList = [];
				this.checkedCities = formData.color ? formData.color.split(",") : [];
				this.handleCheckedCitiesChange(this.checkedCities);
				let fileList = responseData.imageList.split(",");
				for(let i in fileList) {
					var dt = {
						name: "1.png",
						url: fileList[i]
					};

					this.uploadModel.fileList.push(dt);
				}
				if(this.uploadModel.fileList.length > 0) {
					formData.logoUrl = this.uploadModel.fileList[0].url;
				}
				return formData;
			},

			toApiObject(model) {
				let apiObject = {};
				Object.assign(apiObject, model);
				//apiObject.supplierId = "0";
				apiObject.token = this.$store.getters.getToken;
				apiObject.merchantUserId = this.$store.getters.getModel.merchantUserId;
				apiObject.merchantId = this.$store.getters.getMerchantId;
				apiObject.merchantName = "某个商户";

				let fileList = [];
				for(let i in this.uploadModel.fileList) {
					fileList.push(this.uploadModel.fileList[i].url);
				}
				apiObject.color = this.checkedCities.length > 0 ? this.checkedCities.join(",") : '';
				apiObject.imageList = fileList.join(",");

				if(fileList.length > 0) {
					apiObject.logoUrl = fileList[0];
				}
				return apiObject;
			},

			doSubmit() {
				if(!this.goodsModel.editMode) {
					this.$alert("请保存商品后，再继续提交");
					return;
				}
				if(this.goodsModel.goodsName == "") {
					if(this.catfun != "") {
						this.goodsModel.goodsName = this.catfun;
					} else {
						this.$alert("请设置商品名称");
						return false;
					}
				}
				// if (this.$store.getters.getModel.basicMall === "true") {
				//   if (
				//     // !parseFloat(this.goodsModel.labelPrice) > 0 ||
				//     !parseFloat(this.goodsModel.marketPrice) > 0
				//   ) {
				//     this.$message("请设置商品价格");
				//     return false;
				//   }
				// }

				if(
					this.$refs.carMainModel.isHide &&
					(this.$refs.carMainModel.ColumnName || "") == ""
				) {
					this.$message("请设置标题名称");
					return false;
				}
				
//				!re.test(this.$refs.goodsPriceModel.getPrice().star4Price) ||
//				!re.test(this.$refs.goodsPriceModel.getPrice().star5Price)
				if(this.$store.getters.getModel.seniorMall === "true") {
					let priceModel = this.$refs.goodsPriceModel.getPrice();
					let re = /^[0-9]+(.[0-9]{1,2})?$/;
					if(!re.test(this.$refs.goodsPriceModel.getPrice().ownerPrice) ||
						!re.test(this.$refs.goodsPriceModel.getPrice().agentPrice) ||
						!re.test(this.$refs.goodsPriceModel.getPrice().star3Price) 
						
					) {
						this.$alert("会员等级价格格式出错");
						return;
					}

					console.log("===============");
					console.log(priceModel);
					console.log("======end===");
					console.log("this.goodsModel", this.goodsModel);
					Api.updateMemberPrice(this, priceModel, this.goodsModel.goodsId).then(
						res => {
							console.log(res);
							if(!res.retCode) {
								this.$alert("修改成员价格出错！");
								return;
							}
						}
					);
				}

				let model = this.toApiObject(this.goodsModel);
				console.log("本次修改", model);
				console.log(model);

				Api.updateGoods(model)
					.then(res => {
						console.log("修改商品", res, res.retCode);
						
						if(res.retCode == true) {
							this.$message("数据修改成功!");

							this.goodsModel.editMode = true;
							this.$refs.carMainModel.saveColumnItem();

							return;
						} else {
							this.$alert(res.message);
							return;
						}
					})
					.then(res => {
						console.log(res)
						console.log('修改分类')
						let dataModel = {
							goodsId: model.goodsId,
							token: this.$store.getters.getToken,
							merchantUserId: this.$store.getters.getModel.merchantUserId,
							merchantId: this.$store.getters.getMerchantId,

							firstCatId: "",
							secCatId: ""
						};
						if(model.catList.length > 0) {
							dataModel.firstCatId = model.catList[0];
							this.goodsModel.catList[0] = model.catList[0];
						}
						if(model.catList.length > 1) {
							dataModel.secCatId = model.catList[1];
							this.goodsModel.catList[1] = model.catList[1];
						}
						console.log("---", this.goodsModel.catList);
						console.log("data", dataModel);
						Api.changeCategory(dataModel).then(res => {
							console.log(res);
							if(res.retCode) {
								console.log("修改分类成功");
								this.getProDatil();
							}
						});
					});
			},

			validate(model) {
				if(model.editMode == true) {
					this.$alert("信息已经被保存，请提交商品信息");
					return false;
				}
				console.log(this.uploadModel.fileList);
				if(this.uploadModel.fileList.length == 0) {
					this.$alert("至少上传一张图片");
					return false;
				}
				let re = /^[0-9]+(.[0-9]{1,2})?$/;
				if(
					// !re.test(this.goodsModel.labelPrice) ||
					!re.test(this.goodsModel.marketPrice)
				) {
					this.$alert("价格格式出错");
					return false;
				}

				if(model.catList.length == 0) {
					this.$alert("请选择分类信息");
					return false;
				}
				return true;
			},

			doAddGoods(model) {
				let storage = window.localStorage;
				if(this.$store.getters.getModel.basicMall === "true") {
					if(
						// !parseFloat(this.goodsModel.labelPrice) > 0 ||
						!parseFloat(this.goodsModel.marketPrice) > 0
					) {
						this.$message("请设置商品价格");
						return false;
					}
				}
				if(model.goodsName == "") {
					if(this.catfun != "") {
						model.goodsName = this.catfun;
						this.goodsModel.goodsName = this.catfun;
					} else {
						this.$alert("商品名不能为空");
						return false;
					}
				}

				let object = this.toApiObject(model);
				console.log(object);
				if(!this.validate(model)) {
					return;
				}

				let goodsId = "";
				console.log("xxxxxx");
				console.log(object);

				Api.addGoods(object)
					.then(res => {
						console.log(res);
						if(res.retCode) {
							let formObject = this.toFormObject(res.data);

							goodsId = res.data.goodsId;
							// this.goodsModel = {};
							// this.goodsModel = formObject;
							this.goodsModel.goodsId = res.data.goodsId;

							this.goodsModel.editMode = true;
						} else {
							this.$alert(res.message);
							return;
						}
					})
					.then(res => {
						let dataModel = {
							goodsId: goodsId,
							token: this.$store.getters.getToken,
							merchantUserId: this.$store.getters.getModel.merchantUserId,
							merchantId: this.$store.getters.getMerchantId,

							firstCatId: "",
							secCatId: ""
						};
						if(model.catList.length > 0) {
							dataModel.firstCatId = model.catList[0];
							this.goodsModel.catList[0] = model.catList[0];
						}
						if(model.catList.length > 1) {
							dataModel.secCatId = model.catList[1];
							this.goodsModel.catList[1] = model.catList[1];
						}

						Api.changeCategory(dataModel).then(res => {
							if(res.retCode) {
								storage.setItem("catList", JSON.stringify(model.catList));
								storage.setItem("goodsName", model.goodsName);
								storage.setItem("goodsBrand", model.goodsBrand);

								this.$message("商品信息添加成功！");
								this.getProDatil();
							}
						});
					});
			},

			getPdAttribute() {
				Api.getPdAttribute(this, {
					goodsId: this.goodsModel.goodsId
				}).then(res => {
					console.log("查询商品属性", res);

					if(!res.retCode) {
						this.$alert("查询数据错误");
						return;
					}
					this.attributeList = res.data;
				});
			},

			delAttr(row) {
				let model = {
					attributeId: row.id
				};
				let self = this;
				this.$confirm("此操作将永久删除该条属性, 是否继续?", "提示", {
						confirmButtonText: "确定",
						cancelButtonText: "取消",
						type: "warning"
					})
					.then(() => {
						Api.delPdAttribute(self, model).then(res => {
							console.log("删除商品属性", res);

							if(!res.retCode) {
								this.$alert("删除错误");
								return;
							}

							this.$message("删除成功");
							self.getPdAttribute();
						});
					})
					.catch(() => {
						this.$message({
							type: "info",
							message: "已取消删除"
						});
					});
			},
			changeAttributeItem(row) {
				if(this.updateAttrModelId !== row.id) {
					this.updateAttrModelId = row.id;
					return;
				}
				let model = {
					attributeId: row.id,
					goodsId: this.goodsModel.goodsId,
					attributeName: row.attributeKey,
					attributeValue: row.attributeValue
				};
				Api.changePdAttribute(this, model).then(res => {
					console.log("修改商品属性", res);
					if(!res.retCode) {
						this.$alert("保存错误");
						return;
					}
					this.updateAttrModelId = "";
					//this.$message("保存成功");
					console.log('55555')
					this.getPdAttribute();
				});
			},
			getProDatil() {
				Object.assign(this.goodsModel, {
					token: this.$store.getters.getToken,
					merchantUserId: this.$store.getters.getModel.merchantUserId,
					merchantId: this.$store.getters.getMerchantId
				});
				this.uploadModel.uploadUrl = Config.g_upload_url;
				console.log("this.$route.params.goodsId", this.$route.params.goodsId);
				let goodsId = this.$route.params.goodsId;

				console.log("goodsId=" + goodsId);

				if((goodsId || "") != "") {
					console.log("enter detail ");

					Api.queryGoodsDetail(goodsId).then(res => {
						console.log("QQQQUUUUEEERRRGOOODDSSS!");
						console.log("商品详情", res);

						if(!res.retCode) {
							this.$alert("查询数据错误");
							return;
						}

						let formObject = this.toFormObject(res.data);
						this.goodsModel = {};
						this.goodsModel = formObject;
						this.goodsModel.editMode = true;

						this.goodsModel.editMode = true;
						this.getPdAttribute();
					});
				} else {
					let storage = window.localStorage;
					storage.catList ?
						(this.goodsModel.catList = JSON.parse(storage.catList)) :
						"";
					storage.goodsName ?
						(this.goodsModel.goodsName = storage.goodsName) :
						"";
					storage.goodsBrand ?
						(this.goodsModel.goodsBrand = storage.goodsBrand) :
						"";
				}
			}
		},

		components: {
			carGoodsCom,
			goodsPriceCom,
			carMaintain
		},

		mounted() {
			window.myvue = this;

			this.getProDatil();
			this.getUnit()
			Api.queryCatTree(this).then(res => {
				if(res.retCode) {
					this.goodsOptions = res.data;
					console.log(this.goodsOptions);
					this.handleCatfun();
				}
			});
		}
	};
</script>

<!-- Add "scoped" attribute to limit CSS to this component only -->
<style>
	.el-checkbox__input {
		margin-bottom: 5px;
	}
</style>